<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-28 13:56:04
 * @LastEditTime: 2019-08-29 09:22:47
 * @LastEditors: Please set LastEditors
 -->
<script>
	// 初始化 echarts 
	var demoChart = echarts.init(document.getElementById('realTimeInvoke'), 'macarons');
	demoChart.setOption({
		tooltip: {
			trigger: 'item',
			formatter: "{a} <br/>{b} : {c}"
		},
		toolbox: {
			feature: {
				dataView: { readOnly: false },
				restore: {},
				saveAsImage: {}
			}
		},
		legend: {
			orient: 'vertical',
			left: 'left',
			data: []
		},
		calculable: true,
	});
	demoChart.showLoading();

	//每秒执行定时器
	setInterval(function () {
		var seriesname = document.getElementsByName("tx_echarts_pi1[datas][name]");
		var legendval = document.getElementsByName("tx_echarts_pi1[datas][axis][]");
		var seriesval = document.getElementsByName("tx_echarts_pi1[datas][value][]");
		if (seriesname.length > 0 && legendval.length > 0 && seriesval.length > 0 && seriesname[0] != '' && legendval[0] != '' && seriesval[0] != '') {
			var legenddata = [];    //类别数组（实际用来盛放X轴坐标值）
			var seriesdata = [];    //销量数组（实际用来盛放Y坐标值）
			var seriesbum = [];    //销量数组（实际用来盛放Y坐标值）
			for (var i = 0; i < legendval.length; i++) {
				legenddata.push(legendval[i].value);
			}
			for (var j = 0; j < seriesval.length; j++) {
				var series = {};
				series.value = seriesval[j].value;
				series.name = legendval[j].value;
				seriesdata.push(series);
				seriesbum.push(seriesval[j].value);
			}

			demoChart.hideLoading();    //隐藏加载动画
			demoChart.setOption({
				legend: {
					data: legenddata
				},
				series: [
					{
						name: seriesname[0].value,
						type: 'pie',
						radius: '55%',
						center: ['50%', '60%'],
						data: seriesdata,
						itemStyle: {
							emphasis: {
								shadowBlur: 10,
								shadowOffsetX: 0,
								shadowColor: 'rgba(0, 0, 0, 0.5)'
							}
						} 
					}
				]
			});

		}
	}, 1000);

</script>